﻿@model MVCSayDemo.ViewModel.HomeViewModel

@{
    ViewBag.Title = "Index";
    //Layout = null;
}



<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>首页</title>
    <link rel="stylesheet" href="~/Content/bootstrap.min.css">
    <link rel="stylesheet" href="~/Statics/HomePage.css" />
</head>

<body>
    <!-- <img src="imgs/star.jpg" alt=""> -->
    <div class="card">
        <!-- <div class="nav"> -->
        <div class="say">
            <!-- Button trigger modal -->
            <button type="button" class="btn btn-primary publish" data-target="#exampleModal">
                发表说说
            </button>
            <!-- <div class="user"> -->
            <h7>当前用户：@Model.Username</h7>
            <button onclick="done()" class="btn btn-primary publish logout" data-target="#exampleModal">退出登录</button>
            <!-- </div> -->
            <!-- <div class="card-body">
            <div> -->
            <!-- </div> -->
        </div>
    </div>

    @foreach (var msg in Model.Messages)
    {
        <div class="res" @*style="width: 850px;"*@>
            <!-- 说说框 -->
            <div class="card-header" style="height: 80px;">
                <h1 id="SaySay">
                    @*@msg.FromUserName:*@ @msg.Content
                </h1>
                <button type="button" class="btn btn-primary discuss" data-toggle="modal" data-target="#exampleModal"
                        onclick="talk(`{{msg.id}}`)">
                    评论
                </button>
            </div>

            <div class="talk">
                <div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel1" aria-hidden="true">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <h5 class="modal-title" id="exampleModalLabel1">内容</h5>
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                    <span aria-hidden="true">&times;</span>
                                </button>
                            </div>
                            <div class="modal-body">
                                <input type="email" class="form-control" id="exampleInputEmail2" aria-describedby="emailHelp">
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-secondary" data-dismiss="modal">取消评论</button>
                                <button type="button" class="btn btn-primary" data-dismiss="modal" onclick="publishs()">评论</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>


            <!-- 评论框 -->
            <div id="modalbodys">
                <ul class="list-group list-group-flush" id="comes">
                    @foreach (var com in msg.Comments)
                    {
                        <li class="list-group-item">@com.FromUserName：@com.Content</li>
                    }
                </ul>
            </div>
        </div>
    }
    <!-- //发表说说框 -->
    <div id="talkPlace">
        <h2>发表说说</h2>

        <form action="publishs" method="POST">
            <textarea cols="30" rows="10" id="Text" name="Text"></textarea>
            <br>

            <input type="submit" value="发表" id="publish">
            <a href="./"><input type="button" value="取消"></a>

        </form>
    </div>
    <link rel="stylesheet" href="~/Scripts/jquery-3.4.1.min.js">
    <script src="https://cdn.bootcss.com/axios/0.18.0/axios.min.js"></script>
    <link rel="stylesheet" href="~/Scripts/bootstrap.min.js">
    <script>

        let currentId;

        function done() {
            window.location.href = 'Help';
        }

        function talk(MsgId) {
            currentId = MsgId
            $('#review').css("visibility", "visible");
        }

        //评论
        function publishs() {

            let talkText = $('#exampleInputEmail2').val();
            axios({
                method: 'post',
                url: '/talk',
                data: {
                    talkText: talkText,
                    currentId: currentId
                },
            }).then(function (response) {
                let res = response.data;
                console.log(res);
                if (res.code === 200) {
                    let html = `
                            <li class="list-group-item">${res.name}：${res.talk}</li>
                            `;


                    document.getElementById('comes').innerHTML += html;

                } else {
                    console.log('2000判断不通过');
                }
            }).catch((err) => {
                console.log(err);
            });
        }
    </script>
    @*<script src="/js/jquery-3.6.0.min.js"></script>
        <script src="/js/bootstrap.min.js"></script>*@

</body>

</html>